//
//  CZUserTool.m
//  OCKSFWeibo
//
//  Created by 盛 发 况 on 16/4/27.
//  Copyright © 2016年 盛 发 况. All rights reserved.
//

#import "CZUserTool.h"
#import "CZUserParam.h"
#import "CZUserResult.h"
#import "CZHttpTool.h"
#import "CZAccountTool.h"
#import "CZAccount.h"
#import <MJExtension.h>
#import "CZUser.h"

@implementation CZUserTool
/**
 *  请求用户的未读书
 */
+ (void)unreadWithSuccess:(void (^)(CZUserResult *))success failure:(void (^)(NSError *))failure {
    
    CZUserParam *param = [CZUserParam param];
    param.uid = [CZAccountTool account].uid;
    
    [CZHttpTool GET:@"https://rm.api.weibo.com/2/remind/unread_count.json" parameters:param.mj_keyValues success:^(id responseObject) {
        
        // 字典转换模型
        CZUserResult *result = [CZUserResult mj_objectWithKeyValues:responseObject];
        if (success) {
            success(result);
        }
        
        
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}

/**
 *  请求用户的信息
 */
+ (void)userInfoWithSuccess:(void (^)(CZUser *))success failure:(void (^)(NSError *))failure {
    
    CZUserParam *param = [CZUserParam param];
    param.uid = [CZAccountTool account].uid;
    
    [CZHttpTool GET:@"https://api.weibo.com/2/users/show.json" parameters:param.mj_keyValues success:^(id responseObject) {
        
        // 用户字典转换用户模型
        CZUser *user = [CZUser mj_objectWithKeyValues:responseObject];
        if (success) {
            success(user);
        }
        
    } failure:^(NSError *error) {
        
        if (failure) {
            failure(error);
        }
        
    }];
}


@end



